﻿/****************************** Module Header ******************************\

Copyright (c) Gary Davidson

This source is subject to the Microsoft Public License.
See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
All other rights reserved.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System.Linq;

using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Savviety.ServiceManager.Facade.Criteria;
using Savviety.ServiceManager.Facade.ManagementPacks;


namespace Savviety.ServiceManager.Facade
{

    public abstract class SCSMClass
    {
        
    }

    public  class SCSMIncident : SCSMClass
    {

        public static EnterpriseManagementObjectProjection GetIncident(string id)
        {

            var builder = new ProjectionCriteriaBuilder();

            builder.AddReferences(ManagementPackNames.System_WorkItem_Incident_Library, "Incident");

            const string property = "$Target/Property[Type='Incident!System.WorkItem.Incident']/Id$";

            var criteria = builder.CreateSimpleCriteria(TypeProjections.TypeProjections.System_WorkItem_Incident_ProjectionType, property, id);

            return SCSMServer.GetObjectProjectionReader(criteria, ObjectQueryOptions.Default).FirstOrDefault();
        }

 
        public static EnterpriseManagementObjectProjection GetIncidentAndActivities(string id)
        {

            var builder = new ProjectionCriteriaBuilder();

            builder.AddReferences(ManagementPackNames.System_WorkItem_Incident_Library, "Incident");

            const string property = "$Target/Property[Type='Incident!System.WorkItem.Incident']/Id$";


            var criteria = builder.CreateSimpleCriteria(TypeProjections.TypeProjections.System_WorkItem_Incident_Activities_ProjectionType, property, id);

            return SCSMServer.GetObjectProjectionReader(criteria, ObjectQueryOptions.Default).FirstOrDefault();


        }
        public static EnterpriseManagementObject GetIncidentObject(string id)
        {

            return SCSMServer.GetObject<EnterpriseManagementObject>(id);
        }

    }
}
